Imports System.IO
Imports System.Data.SqlClient
Imports System
Imports System.Text
Imports System.Data.Odbc


Public Class FrmBiodata
    Dim GV_PATLOCK_STATUS As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GV_ISNEW_PATIENT = True
        Panel2.Enabled = True
        Panel3.Enabled = True
        ClearText()
        btnEdit.Visible = False
        btnDel.Visible = False
        Button1.Visible = False
        btnSave.Visible = True
        btnCancel.Visible = True
        Lbl_EnBy.Text = "Entered By:"
        Lbl_UpdBy.Text = "Updated By:"
        Lbl_LockBy.Text = "Locked By:"
        BtnLock.Enabled = False

        TxtLastName.Focus()
    End Sub
    Private Sub LoadRace()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("Exec spGetlookup_Value 80", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxRace.DataSource = list
            Me.cbxRace.DisplayMember = "Code_desc"
            Me.cbxRace.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadSalutation()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("EXEC spGetlookup_Value 600", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("CODE_DESC", GetType(String)))
            list.Columns.Add(New DataColumn("CODE", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("CODE_DESC")), "", objReader("CODE_DESC"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("CODE")), "", objReader("CODE"))
                i = i + 1
            Loop
            Me.cbxSalutation.DataSource = list
            Me.cbxSalutation.DisplayMember = "CODE_DESC"
            Me.cbxSalutation.ValueMember = "CODE"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    'Private Sub LoadNationality()
    '    'CbxNationality.Items.Clear()

    '    Dim SqlConnection1 As New SqlConnection()
    '    SqlConnection1 = New SqlConnection(GV_CONNETION)
    '    If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
    '    Dim sqlCmd = New SqlCommand("EXEC spGetlookup_Value 620", SqlConnection1)
    '    Try
    '        Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
    '        Dim i As Integer
    '        i = 1
    '        Dim list As New DataTable
    '        list.Columns.Add(New DataColumn("CODE_DESC", GetType(String)))
    '        list.Columns.Add(New DataColumn("CODE", GetType(String)))
    '        list.Rows.Add(list.NewRow())
    '        list.Rows(0)(0) = ""
    '        list.Rows(0)(1) = ""
    '        Do While objReader.Read
    '            list.Rows.Add(list.NewRow())
    '            list.Rows(i)(0) = IIf(IsDBNull(objReader("CODE_DESC")), "", objReader("CODE_DESC"))
    '            list.Rows(i)(1) = IIf(IsDBNull(objReader("CODE")), "", objReader("CODE"))
    '            i = i + 1
    '           Loop
    '        Me.CbxNationality.DataSource = list
    '        Me.CbxNationality.DisplayMember = "CODE_DESC"
    '        Me.CbxNationality.ValueMember = "Code"
    '    Catch e As Exception
    '        MsgBox(e.Source + e.Message)
    '    End Try

    '    sqlCmd.Cancel()
    '    SqlConnection1.Close()
    '    sqlCmd = Nothing
    '    SqlConnection1.Close()
    'End Sub
    Private Sub ClearText()
        TxtLastName.Clear()
        'TxtFirstName.Clear()
        'TxtMiddleName.Clear()
        TxtOther.Clear()
        txtIC.Clear()
        TxtMRID.Clear()
        TxtAge.Clear()
        txtBirthPlace.Clear()
        CbxGender.SelectedIndex = 0
        ' CbxNationality.SelectedIndex = 0
        cbxRace.SelectedIndex = 0
        txtHAddr1.Clear()
        TxtHAddr2.Clear()
        TxtHCity.Clear()
        TxtHPostal.Clear()
        TxtHPhone.Clear()
        TxtHFax.Clear()
        TxtHState.Clear()
        TxtHCountry.Clear()
        TxtHCellPhone.Clear()
        TxtHEmail.Clear()
        TxtMAddr1.Clear()
        TxtMAddr2.Clear()
        TxtMCity.Clear()
        TxtMPostal.Clear()
        TxtMPhone.Clear()
        '    TxtMFax.Clear()
        TxtMState.Clear()
        TxtCountry.Clear()
        '   TxtMCellPhone.Clear()
        '    TxtMEmail.Clear()

        DOB.Value = "01-01-1950"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Trim(txtIC.Text) = "" Then
            MsgBox("Please enter NRIC.", MsgBoxStyle.Information, "Patient Biodata")
            Exit Sub
        End If
        If Trim(TxtLastName.Text) = "" Then
            MsgBox("Please enter patient last name.", MsgBoxStyle.Information, "Patient Biodata")
            Exit Sub
        End If
        If IsDuplicateNRIC() = True Then
            MsgBox("Duplicate patient NRIC. Please check.", MsgBoxStyle.Information, "Patient Biodata")
            Exit Sub
        End If
        SavePatientBiodata()
        Panel2.Enabled = False
        Panel3.Enabled = False

        Close()
    End Sub
    Function IsDuplicateNRIC() As Boolean
        If GV_ISNEW_PATIENT = False Then
            IsDuplicateNRIC = False
            Exit Function
        Else
            Dim vStr As String
            Dim vPatID As String
            vPatID = ""

            Dim SqlConnection1 As New SqlConnection()
            SqlConnection1 = New SqlConnection(GV_CONNETION)
            If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
            vStr = "select Pt_id1 from patients where ptNRIC ='" & Trim(txtIC.Text) & "'  "
            Dim sqlCmd = New SqlCommand(vStr, SqlConnection1)
            Try
                Dim objReader As SqlDataReader = sqlCmd.ExecuteReader

                Do While objReader.Read
                    vPatID = IIf(IsDBNull(objReader("Pt_id1")), "", objReader("Pt_id1"))
                Loop

            Catch e As Exception
                MsgBox(e.Source)
            End Try

            sqlCmd.Cancel()
            SqlConnection1.Close()
            sqlCmd = Nothing
            SqlConnection1.Close()

            If vPatID = "" Then IsDuplicateNRIC = False Else IsDuplicateNRIC = True
        End If


    End Function
    Private Sub SavePatientBiodata()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertPatient", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()
        '        myCommand.Parameters.Add("@FirstName", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@ptNRIC", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtName", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtBirthDate", SqlDbType.DateTime)
        myCommand.Parameters.Add("@PtGender", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtRace", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtAddress1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtAddress2", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtCity", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtPostalCode", SqlDbType.VarChar)
        myCommand.Parameters.Add("@ptPhone", SqlDbType.VarChar)
        myCommand.Parameters.Add("@ptFax", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtState", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtCountry", SqlDbType.VarChar)
        myCommand.Parameters.Add("@ptCellPhone", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtEmail", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactPerson", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactAddress1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactAddress2", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactCity", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactPostalCode", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactPhone", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactState", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtContactCountry", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtOtherName", SqlDbType.VarChar)
        myCommand.Parameters.Add("@ptMRID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtBirthPlace", SqlDbType.VarChar)
        myCommand.Parameters.Add("@PtTitle", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@UpdatedBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Status", SqlDbType.VarChar)
        
        myCommand.Parameters("@Pt_id1").Value = Trim(TxtPatID.Text)
        myCommand.Parameters("@ptNRIC").Value = Trim(txtIC.Text)
        myCommand.Parameters("@PtName").Value = Trim(TxtLastName.Text)
        myCommand.Parameters("@PtBirthDate").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@PtGender").Value = Trim(CbxGender.Text)
        myCommand.Parameters("@PtRace").Value = Trim(cbxRace.Text)
        myCommand.Parameters("@PtAddress1").Value = Trim(txtHAddr1.Text)
        myCommand.Parameters("@PtAddress2").Value = Trim(TxtHAddr2.Text)
        myCommand.Parameters("@PtCity").Value = Trim(TxtHCity.Text)
        myCommand.Parameters("@PtPostalCode").Value = Trim(TxtHPostal.Text)
        myCommand.Parameters("@ptPhone").Value = Trim(TxtHPhone.Text)
        myCommand.Parameters("@ptFax").Value = Trim(TxtHFax.Text)
        myCommand.Parameters("@PtState").Value = Trim(TxtHState.Text)
        myCommand.Parameters("@PtCountry").Value = Trim(TxtHCountry.Text)
        myCommand.Parameters("@ptCellPhone").Value = Trim(TxtHCellPhone.Text)
        myCommand.Parameters("@PtEmail").Value = Trim(TxtHEmail.Text)
        myCommand.Parameters("@PtContactPerson").Value = Trim(txtContactPerson.Text)
        myCommand.Parameters("@PtContactAddress1").Value = Trim(TxtMAddr1.Text)
        myCommand.Parameters("@PtContactAddress2").Value = Trim(TxtMAddr2.Text)
        myCommand.Parameters("@PtContactCity").Value = Trim(TxtMCity.Text)
        myCommand.Parameters("@PtContactPostalCode").Value = Trim(TxtMPostal.Text)
        myCommand.Parameters("@PtContactPhone").Value = Trim(TxtMPhone.Text)
        '   myCommand.Parameters("@M_Fax").Value = Trim(TxtMFax.Text)
        myCommand.Parameters("@PtContactState").Value = Trim(TxtMState.Text)
        myCommand.Parameters("@PtContactCountry").Value = Trim(TxtCountry.Text)
        '      myCommand.Parameters("@M_CellPhone").Value = Trim(TxtMCellPhone.Text)
        '     myCommand.Parameters("@M_Email").Value = Trim(TxtMEmail.Text)
        '    myCommand.Parameters("@Last_NM").Value = Trim(TxtLastName.Text)
        '    myCommand.Parameters("@First_NM").Value = Trim(TxtFirstName.Text)
        '     myCommand.Parameters("@Middle_NM").Value = Trim(TxtMiddleName.Text)
        myCommand.Parameters("@PtOtherName").Value = Trim(TxtOther.Text)
        myCommand.Parameters("@ptMRID").Value = Trim(TxtMRID.Text)
        myCommand.Parameters("@PtBirthPlace").Value = Trim(txtBirthPlace.Text)
        myCommand.Parameters("@PtTitle").Value = Trim(cbxSalutation.Text)
        '  myCommand.Parameters("@Salutation_ID").Value = Trim(cbxSalutation.SelectedText)
        ' myCommand.Parameters("@Nationality_ID").Value = Trim(CbxNationality.SelectedValue)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.Parameters("@UpdatedBy").Value = GV_USER
        If GV_ISNEW_PATIENT = True Then
            myCommand.Parameters("@Status").Value = "A"
        Else
            myCommand.Parameters("@Status").Value = "E"
        End If

        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        If Trim(txtIC.Text) = "" Then Exit Sub
        GV_ISNEW_PATIENT = False
        Panel2.Enabled = True
        Panel3.Enabled = True
        Button1.Visible = False
        btnDel.Visible = False
        btnEdit.Visible = False
        btnSave.Visible = True
        btnCancel.Visible = True
        TxtLastName.Focus()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        If Trim(txtIC.Text) = "" Then
            Exit Sub
        End If
        Dim response As Integer

        response = MsgBox("Are you sure want to delete this record?", MsgBoxStyle.YesNo, "Delete")
        If response = 7 Then
            Exit Sub
        End If

        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spDelPatient", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters("@Pt_id1").Value = Trim(TxtPatID.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing
        Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        'MsgBox(Me.CbxNationality.SelectedValue)
        If GV_ISNEW_PATIENT = True Then ClearText()
        Panel2.Enabled = False
        Panel3.Enabled = False
        Button1.Visible = True
        btnEdit.Visible = True
        btnDel.Visible = True
        btnSave.Visible = False
        btnCancel.Visible = False
    End Sub

  
    Private Sub FrmBiodata_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If GV_CUR_PATID <> "" Then
        ' LoadNationality()
        FrmMain.LoadUserSecurity_Biodata()
        LoadSalutation()
        LoadRace()
        LoadGender()
        If GV_CUR_PATID <> "" Then
            LoadPatient()
            'If GV_FRMBIODATA_ALLOW_EDIT = True Then
            '    btnEdit_Click(sender, e)
            'Else
            '    Panel1.Enabled = False
            'End If
        End If
        Button1.Enabled = GV_FRMBIODATA_ALLOW_ADD
        btnEdit.Enabled = GV_FRMBIODATA_ALLOW_EDIT
        btnSave.Enabled = GV_FRMBIODATA_ALLOW_ADD
        btnDel.Enabled = GV_FRMBIODATA_ALLOW_DELETE

        If GV_PATLOCK_STATUS = "P" Then
            BtnLock.Text = "Unlock"
            btnEdit.Enabled = False
            btnSave.Enabled = False
            btnDel.Enabled = False
        Else
            BtnLock.Text = "Lock"
        End If

    End Sub
    Private Sub LoadGender()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 81", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.CbxGender.DataSource = list
            Me.CbxGender.DisplayMember = "Code_desc"
            Me.CbxGender.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source + e.Message)
        End Try
    End Sub
    Private Sub LoadPatient()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select * from patients where Pt_id1 = '" & GV_CUR_PATID & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                TxtPatID.Text = IIf(IsDBNull(objReader("Pt_id1")), "", objReader("Pt_id1"))
                txtIC.Text = IIf(IsDBNull(objReader("ptNRIC")), "", objReader("ptNRIC"))
                TxtLastName.Text = IIf(IsDBNull(objReader("PtName")), "", objReader("PtName"))
                '    TxtFirstName.Text = IIf(IsDBNull(objReader("First_NM")), "", objReader("First_NM"))
                '   TxtMiddleName.Text = IIf(IsDBNull(objReader("Middle_NM")), "", objReader("Middle_NM"))
                DOB.Value = IIf(IsDBNull(objReader("PtBirthDate")), "01/01/1900", objReader("PtBirthDate"))
                txtHAddr1.Text = IIf(IsDBNull(objReader("PtAddress1")), "", objReader("PtAddress1"))
                TxtHAddr2.Text = IIf(IsDBNull(objReader("PtAddress2")), "", objReader("PtAddress2"))
                TxtHCity.Text = IIf(IsDBNull(objReader("PtCity")), "", objReader("PtCity"))
                TxtHPostal.Text = IIf(IsDBNull(objReader("PtPostalCode")), "", objReader("PtPostalCode"))
                TxtHPhone.Text = IIf(IsDBNull(objReader("ptPhone")), "", objReader("ptPhone"))
                TxtHFax.Text = IIf(IsDBNull(objReader("ptFax")), "", objReader("ptFax"))
                TxtHState.Text = IIf(IsDBNull(objReader("PtState")), "", objReader("PtState"))
                TxtHCountry.Text = IIf(IsDBNull(objReader("PtCountry")), "", objReader("PtCountry"))
                TxtHCellPhone.Text = IIf(IsDBNull(objReader("ptCellPhone")), "", objReader("ptCellPhone"))
                TxtHEmail.Text = IIf(IsDBNull(objReader("PtEmail")), "", objReader("PtEmail"))
                txtContactPerson.Text = IIf(IsDBNull(objReader("PtContactPerson")), "", objReader("PtContactPerson"))
                TxtMAddr1.Text = IIf(IsDBNull(objReader("PtContactAddress1")), "", objReader("PtContactAddress1"))
                TxtMAddr2.Text = IIf(IsDBNull(objReader("PtContactAddress2")), "", objReader("PtContactAddress2"))
                TxtMCity.Text = IIf(IsDBNull(objReader("PtContactCity")), "", objReader("PtContactCity"))
                TxtMPostal.Text = IIf(IsDBNull(objReader("PtContactPostalCode")), "", objReader("PtContactPostalCode"))
                TxtMPhone.Text = IIf(IsDBNull(objReader("PtContactPhone")), "", objReader("PtContactPhone"))
                '  TxtMFax.Text = IIf(IsDBNull(objReader("M_Fax")), "", objReader("M_Fax"))
                TxtMState.Text = IIf(IsDBNull(objReader("PtContactState")), "", objReader("PtContactState"))
                TxtCountry.Text = IIf(IsDBNull(objReader("PtContactCountry")), "", objReader("PtContactCountry"))
                '  TxtMCellPhone.Text = IIf(IsDBNull(objReader("M_CellPhone")), "", objReader("M_CellPhone"))
                '  TxtMEmail.Text = IIf(IsDBNull(objReader("M_Email")), "", objReader("M_Email"))
                TxtOther.Text = IIf(IsDBNull(objReader("PtOtherName")), "", objReader("PtOtherName"))
                TxtMRID.Text = IIf(IsDBNull(objReader("ptMRID")), "", objReader("ptMRID"))
                txtBirthPlace.Text = IIf(IsDBNull(objReader("PtBirthPlace")), "", objReader("PtBirthPlace"))
                cbxSalutation.Text = IIf(IsDBNull(objReader("PtTitle")), "", objReader("PtTitle"))
                '        CbxNationality.SelectedValue = IIf(IsDBNull(objReader("Nationality_ID")), "", objReader("Nationality_ID"))
                CbxGender.Text = IIf(IsDBNull(objReader("PtGender")), "MALE", objReader("PtGender"))
                cbxRace.Text = IIf(IsDBNull(objReader("PtRace")), "", objReader("PtRace"))
                TxtAge.Text = IIf(IsDBNull(objReader("PtAge")), "", objReader("PtAge"))
                Lbl_EnBy.Text = Lbl_EnBy.Text & vbCrLf & IIf(IsDBNull(objReader("EnteredBy")), "", objReader("EnteredBy"))
                Lbl_UpdBy.Text = Lbl_UpdBy.Text & vbCrLf & IIf(IsDBNull(objReader("UpdatedBy")), "", objReader("UpdatedBy"))
                Lbl_LockBy.Text = Lbl_LockBy.Text & vbCrLf & IIf(IsDBNull(objReader("LockedBy")), "", objReader("LockedBy"))
                GV_PATLOCK_STATUS = IIf(IsDBNull(objReader("LockedBy")), "A", "P")
            Loop

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    
    Private Sub BtnLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLock.Click
        If BtnLock.Text = "Lock" Then
            If GV_FRMBIODATA_ALLOW_APPROVE = False Then
                MsgBox("Permission denied.", MsgBoxStyle.Information)
                Exit Sub
            End If
        End If

        If BtnLock.Text = "UnLock" Then
            If GV_FRMBIODATA_ALLOW_UNAPPROVE = False Then
                MsgBox("Permission denied.", MsgBoxStyle.Information)
                Exit Sub
            End If
        End If

        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("sp_LockUnlockPatient", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@LockFlag", SqlDbType.VarChar)

        myCommand.Parameters("@Pt_id1").Value = Trim(TxtPatID.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.Parameters("@LockFlag").Value = Trim(BtnLock.Text)
        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing

        If BtnLock.Text = "Lock" Then
            BtnLock.Text = "UnLock"
            btnEdit.Enabled = False
            btnSave.Enabled = False
            btnDel.Enabled = False
            Lbl_LockBy.Text = "Locked By:" & vbCrLf & GV_USERNAME
        Else
            BtnLock.Text = "Lock"
            btnEdit.Enabled = GV_FRMBIODATA_ALLOW_EDIT
            btnSave.Enabled = GV_FRMBIODATA_ALLOW_ADD
            btnDel.Enabled = GV_FRMBIODATA_ALLOW_DELETE
            Lbl_LockBy.Text = "Locked By:"
        End If



    End Sub
End Class